/*
*
* Copyright (c) 2011 Vaulting Systems International
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy 
* of this software and associated documentation files (the "Software"), to deal 
* in the Software without restriction, including without limitation the rights 
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
* of the Software, and to permit persons to whom the Software is furnished to do  
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all  
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE  
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package com.ekeymanlib.business;

import java.util.List;

import com.ekeymanlib.domain.User;
import com.ekeymanlib.dto.AppDeviceApiKeys;
import com.ekeymanlib.dto.AppDeviceGrid;
import com.ekeymanlib.dto.Application;
import com.ekeymanlib.dto.EncryptionKeys;
import com.ekeymanlib.dto.ResourceGrid;
import com.ekeymanlib.dto.SearchFilter;
import com.ekeymanlib.dto.VendorProfile;

public class DefaultKeyManager extends AbstractKeyManager{

	@Override
	public AppDeviceApiKeys registerAppDevice(String apiKey,
			String application, String device) {
		
		return doRegisterAppDevice(apiKey, application, device);
	}
	
	@Override
	public EncryptionKeys createEncryptionKeys(String resourceUri, 
			String publicKey, int keyBytesLength, int ivBytesLength, 
			int saltBytesLength, int iterationCountMax, 
			String location, String digitalSignature) {

		return doCreateEncryptionKeys(resourceUri, 
				publicKey, keyBytesLength, ivBytesLength, 
				saltBytesLength, iterationCountMax, 
				location, digitalSignature);
	}

	public void deleteEncryptionKeys(String resourceUri, String publicKey,
			String location, String digitalSignature) {

		doDeleteEncryptionKeys(resourceUri, publicKey,
				location, digitalSignature);
		
	}
	
	public void deleteResourceById(long id, String apiKey) {
		doDeleteResourceById(id, apiKey);
	}
	
	public void deleteAppDeviceById(long id, String apiKey) {
		doDeleteAppDeviceById(id, apiKey);
	}
	
	public long getAppDeviceCount(List<SearchFilter> searchFilters){
		return doGetAppDeviceCount(searchFilters);
	}
	
	public List<AppDeviceGrid> findAppDevices(List<SearchFilter> searchFilters, 
			String sortIndex, String sortOrder, int firstResult, int maxResults){
		return doFindAppDevices(searchFilters, 
				sortIndex, sortOrder, firstResult, maxResults);
	}

	public long getResourceCount(List<SearchFilter> searchFilters){
		return doGetResourceCount(searchFilters);
	}
	
	public List<ResourceGrid> findResources(List<SearchFilter> searchFilters, 
			String sortIndex, String sortOrder, int firstResult, int maxResults){
		return doFindResources(searchFilters, 
				sortIndex, sortOrder, firstResult, maxResults);
	}

	
	@Override
	public void deleteVendor(String username) {

		doDeleteVendor(username);
		
	}

	@Override
	public AppDeviceApiKeys generateNewPrivateKey(String publicKey, String apiKey) {

		return doGenerateNewPrivateKey(publicKey, apiKey);
	}

	@Override
	public EncryptionKeys getEncryptionKeys(String resourceUri,
			String publicKey, String location, String digitalSignature) {

		return doGetEncryptionKeys(resourceUri,
				publicKey, location, digitalSignature);
	}

	@Override
	public VendorProfile getVendorProfile(String apiKey) {

		return doGetVendorProfile(apiKey);
	}

	@Override
	public String registerVendor(String name,
			String address, String city, String state, String zip, 
			String phone, String emailAddress) {

		return doRegisterVendor(name, address, city,
				state, zip, phone, emailAddress);
	}

	@Override
	public void updateVendor(String apiKey, String name, 
			String address, String city, String state, String zip, 
			String phone, String emailAddress) {

		doUpdateVendor(apiKey, name, address, city,
				state, zip, phone, emailAddress);
		
	}

	@Override
	public User getUser(String openidurl) {
		return doGetUser(openidurl);
	}

	@Override
	public void registerUser(String apiKey, String openidurl) {
		doRegisterUser(apiKey, openidurl);
	}

	@Override
	public void deleteUser(String openidurl) {
		doDeleteUser(openidurl);
	}

	@Override
	public List<Application> listApplications(String apiKey) {
		return doListApplications(apiKey);
	}

}
